package com.guyaning.deyson_core.core.net;

import android.content.Context;

import com.guyaning.deyson_core.core.net.callback.IError;
import com.guyaning.deyson_core.core.net.callback.IFailure;
import com.guyaning.deyson_core.core.net.callback.IRequest;
import com.guyaning.deyson_core.core.net.callback.ISuccess;
import com.guyaning.deyson_core.core.ui.loader.LoaderStyle;

import java.io.File;
import java.util.Map;
import java.util.WeakHashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2018/4/10.
 */

public class RestClientBuilder {

    private String mUrl = null;

    private static  final WeakHashMap<String,Object> PARAMS = RestCreator.getParams();

    private IRequest mIrequest = null;

    private ISuccess mIsuccess = null;

    private IError mIerror = null;

    private RequestBody mBody = null;

    private IFailure mIfailure = null;

    private LoaderStyle mLoaderStyle = null;

    private Context mContext = null;

    private File mFile = null;

    private String mDownloadDir = null;

    private String mExtension = null;

    private String mName = null;

    RestClientBuilder(){

    }

    public final RestClientBuilder url(String url){
        this.mUrl = url;
        return this;
    }

    public final RestClientBuilder params(Map<String,Object> params){
        PARAMS.putAll(params);
        return this;
    }

    public final RestClientBuilder file(File file){
       this.mFile = file;
        return this;
    }

    public final RestClientBuilder file(String file){
        this.mFile = new File(file);
        return this;
    }

    public final RestClientBuilder name(String name) {
        this.mName = name;
        return this;
    }

    public final RestClientBuilder dir(String dir) {
        this.mDownloadDir = dir;
        return this;
    }

    public final RestClientBuilder extension(String extension) {
        this.mExtension = extension;
        return this;
    }

    public final RestClientBuilder params(String key,Object value){
        PARAMS.put(key,value);
        return this;
    }

    public final RestClientBuilder row(String row){
        this.mBody = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"),row);
        return this;
    }

    public final RestClientBuilder success(ISuccess iSuccess){
        this.mIsuccess = iSuccess;
        return this;
    }

    public final RestClientBuilder failure(IFailure iFailure){
        this.mIfailure = iFailure;
        return this;
    }

    public final RestClientBuilder error(IError iError){
        this.mIerror = iError;
        return this;
    }

    public final RestClientBuilder request(IRequest iRequest){
        this.mIrequest = iRequest;
        return this;
    }

    public final RestClientBuilder loader(Context context,LoaderStyle style){
        this.mContext = context;
        this.mLoaderStyle = style;
        return  this;
    }

    public final RestClientBuilder loader(Context context){
        this.mContext = context;
        this.mLoaderStyle = LoaderStyle.BallSpinFadeLoaderIndicator;
        return  this;
    }

    public final RestClient build(){
        return new RestClient(mUrl,PARAMS,mDownloadDir,mExtension,mName,mIrequest,mIsuccess,mIerror,mBody,mIfailure,mFile,mLoaderStyle,mContext);
    }


}
